package com.ruoyi.web.controller.ydz;

import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.Country;
import com.ruoyi.web.service.ICountryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 国家管理Controller
 * 
 * @author drx
 * @date 2024-03-25
 */
@Controller
@RequestMapping({"/ydz/country","/api/country"})
@Api(tags = "国家管理")
public class CountryController extends BaseController
{
    private String prefix = "ydz/country";

    @Autowired
    private ICountryService countryService;

    @RequiresPermissions("ydz:country:view")
    @GetMapping()
    public String country()
    {
        return prefix + "/country";
    }

    /**
     * 查询国家管理列表
     */
    @RequiresPermissions("ydz:country:list")
    @PostMapping("/list")
    @ResponseBody
    @ApiOperation("查询国家管理列表")
    public TableDataInfo list(Country country)
    {
        startPage();
        List<Country> list = countryService.selectCountryList(country);
        return getDataTable(list);
    }

    /**
     * 查询国家管理列表
     */
    @PostMapping("/getCountryList")
    @ResponseBody
    @ApiOperation("查询国家管理列表")
    public TableDataInfo getCountryList(Country country)
    {
        startPage();
        List<Country> list = countryService.selectCountryList(country);
        return getDataTable(list);
    }

    /**
     * 导出国家管理列表
     */
    @RequiresPermissions("ydz:country:export")
    @Log(title = "国家管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    @ApiOperation("导出国家管理列表")
    public AjaxResult export(Country country)
    {
        List<Country> list = countryService.selectCountryList(country);
        ExcelUtil<Country> util = new ExcelUtil<Country>(Country.class);
        return util.exportExcel(list, "国家管理数据");
    }

    /**
     * 新增国家管理
     */
    @GetMapping("/add")
    @ApiOperation("新增国家管理")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存国家管理
     */
    @ApiOperation("新增保存国家管理")
    @RequiresPermissions("ydz:country:add")
    @Log(title = "国家管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Country country)
    {
        return toAjax(countryService.insertCountry(country));
    }

    /**
     * 修改国家管理
     */
    @ApiOperation("修改国家管理")
    @RequiresPermissions("ydz:country:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Country country = countryService.selectCountryById(id);
        mmap.put("country", country);
        return prefix + "/edit";
    }

    /**
     * 修改保存国家管理
     */
    @ApiOperation("修改保存国家管理")
    @RequiresPermissions("ydz:country:edit")
    @Log(title = "国家管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Country country)
    {
        return toAjax(countryService.updateCountry(country));
    }

    /**
     * 删除国家管理
     */
    @ApiOperation("删除国家管理")
    @RequiresPermissions("ydz:country:remove")
    @Log(title = "国家管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(countryService.deleteCountryByIds(ids));
    }

    /**
     * 获取国家详情
     */
    @ApiOperation("获取国家详情")
    @GetMapping("/getCountryById/{id}")
    @ResponseBody
    public AjaxResult getCountryById(@PathVariable("id") Long id)
    {
        return countryService.getCountryById(id);
    }

}
